import { createReducer, on } from '@ngrx/store';
import { EditorActions } from '../actions/editor-action';
import { SelectedGraphObjectState, ZoomOperationState } from '../models/editor-model';

export const editorFeatureKey = 'editor';
export const editorZoomFeatureKey = 'editorZoom';

export const initialState: SelectedGraphObjectState = {
  type: 'CANVAS'
};

export const editorReducer = createReducer(
  initialState,
  on(
    EditorActions.selectChange,
    // eslint-disable-next-line @ngrx/on-function-explicit-return-type
    (state: SelectedGraphObjectState, { payload }) => {
      // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
      const  cloneState = <SelectedGraphObjectState>JSON.parse(JSON.stringify(state));
      cloneState.type = payload.type;
      cloneState.obj = payload.obj;
      return { ...cloneState};
    }
  ),

);
export const initialZoomState: ZoomOperationState = {

};

export const editorZoomReducer = createReducer(
  initialZoomState,
  on(
    EditorActions.zoomOperation,
    // eslint-disable-next-line @ngrx/on-function-explicit-return-type
    (state: ZoomOperationState, { payload }) => {
      // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
      const  cloneState = <ZoomOperationState>JSON.parse(JSON.stringify(state));
      cloneState.type = payload.type;
      return { ...cloneState};
    }
  ),

);
